/**
 * 需求： 需要一个可以判断出输入值是什么类型数值的类
 */
class judge {
    constructor(value) {
        this.value = value;
    }
    judgeValue() {
        let temp = this.value;
        const basicType = (temp) => {
            // console.log(temp, 435)
            if (typeof temp === 'number') {
                return 'number'
            } 
            if (typeof temp === 'string') {
                return 'string'
            }
            if (typeof temp === 'boolean') {
                return 'boolean'
            }
            if (typeof temp === 'undefined') {
                return 'undefined'
            }
          
            if (Object.prototype.toString.call(temp) === '[object Null]') {
                return 'Null'
            }
            return false;
        }
        const objectType = (temp) => {
            if (Object.prototype.toString.call(temp) === '[object Array]') {
                return 'Array'
            }
            if (Object.prototype.toString.call(temp) === '[object Object]') {
                return 'Object'
            }
            if (typeof temp === 'function') {
                return 'function'
            }
        } 
        if (!basicType(temp)) {
            let type = objectType(temp);
            if (type === 'Array') {
                let newArray = [];
                for (let i = 0 ; i < temp.length; i++) {
                    let arrayItemType = basicType(temp[i]);
                    if (arrayItemType === false) {
                        newArray.push(objectType(temp[i]));
                    } else {
                        newArray.push(arrayItemType);
                    }
                }
                console.log(newArray)
                return newArray;
            } else if (type === 'Object') {
                const newObjcet = {};
                Object.keys(temp).forEach(e => {
                    let objectItemType = basicType(temp[e]);
                    const keyArr = Object.keys(temp);

                    for (let j = 0; j < keyArr.length; j++) {
                    if (objectItemType === false) {
                        console.log(e)
                        newObjcet[`${keyArr[j]}`] = objectType(temp[e]);
                    } else {
                        newObjcet[`${keyArr[j]}`] = objectItemType;
                    }
                }

                });
                console.log(newObjcet);
                return newObjcet;
            }

        }
    }
    
}
// const arr = ['null', function(){}, 132, {name: 'Jay', age: 19}, [1,2,3]]
const arr = {name: 'hello', age: 198, arr: []};
const temp = new judge(arr);
temp.judgeValue();